home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / gamma-bros.swf / scripts / __Packages / classes / enemy / BatC.as < prev    next >
Encoding:
Text File  |  2011-10-17  |  17.9 KB  |  617 lines

  1. class classes.enemy.BatC
  2. {
  3.    var x;
  4.    var y;
  5.    var moveScript;
  6.    var matrixCoords;
  7.    var form;
  8.    var id;
  9.    var clip;
  10.    var colorR;
  11.    var trans;
  12.    var colorTrans;
  13.    var advanceMax;
  14.    var advanceMax2;
  15.    var matrixVar;
  16.    var dir;
  17.    var f2;
  18.    var axis;
  19.    var xDest;
  20.    var yDest;
  21.    var oldDir;
  22.    var xMov = 0;
  23.    var yMov = 0;
  24.    var xmt = 0;
  25.    var ymt = 0;
  26.    var xMovT = 0;
  27.    var yMovT = 0;
  28.    var speedOrig = 11;
  29.    var speed = 11;
  30.    var xDestMet = false;
  31.    var yDestMet = false;
  32.    var c = 0;
  33.    var feelerInfo = [[-400,0,400,40],[0,0,400,40],[0,-400,40,400],[0,0,40,400]];
  34.    var dirArray = ["L","R","U","D"];
  35.    var pUp = false;
  36.    var life = 20;
  37.    var nudging = false;
  38.    var nc = 0;
  39.    var xA = 0;
  40.    var yA = 0;
  41.    var power = 20;
  42.    var cv = 1;
  43.    var Name = "batC";
  44.    function BatC(px, py, pmoveScript, pmatrixCoords, pform, pid)
  45.    {
  46.       this.x = px;
  47.       this.y = py;
  48.       this.moveScript = pmoveScript.slice();
  49.       this.matrixCoords = pmatrixCoords.slice();
  50.       this.form = pform.slice();
  51.       this.id = pid;
  52.       _root.d = _root.d + 1;
  53.       this.clip = _root.attachMovie("batC","batC" + this.id + "Clip",_root.d + 50000);
  54.       this.clip._x = this.x;
  55.       this.clip._y = this.y;
  56.       this.speed *= _root.dif.speed;
  57.       this.speedOrig = this.speed;
  58.       this.life *= _root.dif.life;
  59.       this.colorR = _root.randRange(-30,30);
  60.       this.trans = new flash.geom.Transform(this.clip);
  61.       this.colorTrans = new flash.geom.ColorTransform(1,1,1,1,this.colorR,this.colorR,this.colorR,0);
  62.       this.trans.colorTransform = this.colorTrans;
  63.       this.advanceMax = 60 / (this.speed / 2);
  64.       this.advanceMax2 = 50 / (this.speed / 2);
  65.       if(this.matrixCoords[0] == "free")
  66.       {
  67.          this.matrixVar = 0;
  68.       }
  69.       else
  70.       {
  71.          this.matrixVar = 1;
  72.       }
  73.       this.speedVar();
  74.       if(random(100) > 92)
  75.       {
  76.          this.pUp = true;
  77.       }
  78.       this.parseMoveScript();
  79.       _root.stats.created = _root.stats.created + 1;
  80.    }
  81.    function broBehind()
  82.    {
  83.       this.dir = _root.advanceDir;
  84.    }
  85.    function bombed(num)
  86.    {
  87.       this.f2 = "death";
  88.    }
  89.    function nudge(pxA, pyA, pscale)
  90.    {
  91.       this.nc = 0;
  92.       this.nudging = true;
  93.       var _loc2_ = pscale / 100;
  94.       this.xA = pxA * _loc2_;
  95.       this.yA = pyA * _loc2_;
  96.    }
  97.    function speedVar()
  98.    {
  99.       if(random(3) == 1)
  100.       {
  101.          this.speed *= _root.randRange2(0.9999,1.0001);
  102.       }
  103.    }
  104.    function twist()
  105.    {
  106.       this.clip.body.gotoAndPlay("twist");
  107.    }
  108.    function parseMoveScript()
  109.    {
  110.       this.dir = this.moveScript[0];
  111.       if(this.dir == "break")
  112.       {
  113.          delete this.moveScript;
  114.          this[this.axis + "MovT"] = 0;
  115.          if(this.matrixCoords[0] == "free")
  116.          {
  117.             this.f2 = "wander";
  118.             this.axis = random(10) <= 4 ? "y" : "x";
  119.             this[this.axis + "MovT"] = random(2) <= 0 ? -1 * this.speed : this.speed;
  120.             this.speedVar();
  121.             this.getDirString();
  122.          }
  123.          else
  124.          {
  125.             this.xDest = _root.advanceDir != "L" ? this.matrixCoords[0] * 60 : this.matrixCoords[0] * 60 + 320;
  126.             this.yDest = this.matrixCoords[1] * 50 + 10;
  127.             this.axis = Math.abs(this.xDest - this.x) <= Math.abs(this.yDest - this.y) ? "y" : "x";
  128.             this[this.axis + "MovT"] = this[this.axis + "Dest"] <= this[this.axis] ? -1 * this.speed : this.speed;
  129.             this.getDirString();
  130.             this.speedVar();
  131.             this.f2 = "gotoMatrix";
  132.          }
  133.       }
  134.       else
  135.       {
  136.          this[this.axis + "MovT"] = 0;
  137.          this.f2 = "gotoXYDest";
  138.          this.axis = !(this.dir == "L" || this.dir == "R") ? "y" : "x";
  139.          this[this.axis + "MovT"] = !(this.dir == "L" || this.dir == "U") ? this.speed : -1 * this.speed;
  140.          this.speedVar();
  141.          if(this.dir == "L" || this.dir == "U")
  142.          {
  143.             this[this.axis + "Dest"] = this[this.axis] - this.moveScript[1];
  144.          }
  145.          else
  146.          {
  147.             this[this.axis + "Dest"] = this[this.axis] + this.moveScript[1];
  148.          }
  149.          this.moveScript.splice(0,2);
  150.       }
  151.    }
  152.    function gotoXYDest()
  153.    {
  154.       if(Math.abs(this[this.axis + "Dest"] - this[this.axis]) < this.speed + 1)
  155.       {
  156.          if(this.axis == "x")
  157.          {
  158.             this.x = this.xDest;
  159.          }
  160.          else
  161.          {
  162.             this.y = this.yDest;
  163.          }
  164.          this.parseMoveScript();
  165.       }
  166.    }
  167.    function gotoMatrix()
  168.    {
  169.       if(Math.abs(this[this.axis + "Dest"] - this[this.axis]) < this.speed + 1)
  170.       {
  171.          if(this.axis == "x")
  172.          {
  173.             this.x = this.xDest;
  174.          }
  175.          else
  176.          {
  177.             this.y = this.yDest;
  178.          }
  179.          this[this.axis + "MovT"] = 0;
  180.          this.axis = this.axis != "x" ? "x" : "y";
  181.          this[this.axis + "MovT"] = this[this.axis + "Dest"] <= this[this.axis] ? -1 * this.speed : this.speed;
  182.          this.getDirString();
  183.          this.speed = this.speedOrig;
  184.       }
  185.       if(Math.abs(this.x - this.xDest) < this.speed + 1 && Math.abs(this.y - this.yDest) < this.speed + 1)
  186.       {
  187.          this.x = this.clip._x = this.xDest;
  188.          this.y = this.clip._y = this.yDest;
  189.          this.xMovT = this.xMov = 0;
  190.          this.yMovT = this.yMov = 0;
  191.          this.matrixVar = 2;
  192.          this.dir = _root.advanceDir;
  193.          _root.matrixNum = _root.matrixNum + 1;
  194.          if(_root.matrixNum >= _root.matrixSize)
  195.          {
  196.             _root.matrixComplete = true;
  197.          }
  198.          _root["formB" + this.form[0]] = "matrixed";
  199.          this.f2 = "wait";
  200.       }
  201.    }
  202.    function getDirString()
  203.    {
  204.       if(this.xMovT < -1)
  205.       {
  206.          this.dir = "L";
  207.       }
  208.       else if(this.xMovT > 1)
  209.       {
  210.          this.dir = "R";
  211.       }
  212.       else if(this.yMovT > 1)
  213.       {
  214.          this.dir = "D";
  215.       }
  216.       else if(this.yMovT < -1)
  217.       {
  218.          this.dir = "U";
  219.       }
  220.    }
  221.    function wait()
  222.    {
  223.       if(random(1000) >= 998 + _root.dif.wait && _root.matrixComplete)
  224.       {
  225.          this.dir = this.findDir();
  226.          if(this.dir == _root.advanceDir)
  227.          {
  228.             this.matrixVar = 0;
  229.             if(random(2) == 1)
  230.             {
  231.                this.xMovT = 0;
  232.                this.power = 30;
  233.                this.f2 = "launching";
  234.                this.c = 0;
  235.             }
  236.             else
  237.             {
  238.                this.clip.body.gotoAndPlay("spread");
  239.                this.xMovT = _root.advanceDir != "L" ? this.speed : -1 * this.speed;
  240.                this.cv = 2;
  241.                this.f2 = "attacking";
  242.             }
  243.          }
  244.          else if(this.dir == "U" || this.dir == "D")
  245.          {
  246.             this.axis = !(this.dir == "L" || this.dir == "R") ? "y" : "x";
  247.             this[this.axis + "MovT"] = !(this.dir == "L" || this.dir == "U") ? this.speed : -1 * this.speed;
  248.             this.matrixVar = 0;
  249.             this.c = 0;
  250.             this.f2 = "leavingMatrix";
  251.          }
  252.       }
  253.    }
  254.    function evade()
  255.    {
  256.       if(this.matrixVar == 2)
  257.       {
  258.          this.matrixVar = 0;
  259.          if(random(2) == 1)
  260.          {
  261.             this.f2 = "wander";
  262.             this[this.axis + "MovT"] = 0;
  263.             this.axis = random(10) <= 4 ? "y" : "x";
  264.             this[this.axis + "MovT"] = random(2) <= 0 ? -1 * this.speed : this.speed;
  265.             this.speedVar();
  266.             this.getDirString();
  267.          }
  268.          else
  269.          {
  270.             this.clip.body.gotoAndPlay("spread");
  271.             this.xMovT = _root.advanceDir != "L" ? this.speed : -1 * this.speed;
  272.             this.f2 = "attacking";
  273.          }
  274.       }
  275.    }
  276.    function launching()
  277.    {
  278.       this.c = this.c + 1;
  279.       if(this.c == 1)
  280.       {
  281.          this.clip.body.gotoAndPlay("launch");
  282.          _root.audio.playLevel2("batCLaunch",30);
  283.       }
  284.       if(this.c == 42)
  285.       {
  286.          this.xMovT = _root.advanceDir != "L" ? 2 : -2;
  287.          this.xMov = _root.advanceDir != "L" ? 2 : -2;
  288.       }
  289.       if(this.c == 43)
  290.       {
  291.          this.xMovT = _root.advanceDir != "L" ? 4 : -4;
  292.          this.xMov = _root.advanceDir != "L" ? 4 : -4;
  293.       }
  294.       if(this.c == 44)
  295.       {
  296.          this.xMovT = _root.advanceDir != "L" ? 10 : -10;
  297.          this.xMov = _root.advanceDir != "L" ? 10 : -10;
  298.       }
  299.       if(this.c == 45)
  300.       {
  301.          this.xMovT = _root.advanceDir != "L" ? 25 : -25;
  302.          this.xMov = _root.advanceDir != "L" ? 25 : -25;
  303.       }
  304.       if(this.c == 46)
  305.       {
  306.          this.xMovT = _root.advanceDir != "L" ? 54 : -54;
  307.          this.xMov = _root.advanceDir != "L" ? 54 : -54;
  308.          this.f2 = "attacking2";
  309.       }
  310.    }
  311.    function leavingMatrix()
  312.    {
  313.       this.c = this.c + 1;
  314.       if(this.c > this.advanceMax2)
  315.       {
  316.          this.c = 0;
  317.          this.dir = this.findDir();
  318.          if(this.dir == _root.advanceDir)
  319.          {
  320.             this.yMovT = 0;
  321.             this.clip.body.gotoAndPlay("spread");
  322.             if(random(2) == 1)
  323.             {
  324.                this.xMovT = 0;
  325.                this.f2 = "launching";
  326.                this.c = 0;
  327.             }
  328.             else
  329.             {
  330.                this.xMovT = _root.advanceDir != "L" ? this.speed : -1 * this.speed;
  331.                this.cv = 2;
  332.                this.f2 = "attacking";
  333.             }
  334.          }
  335.       }
  336.    }
  337.    function findDir()
  338.    {
  339.       _root.d = _root.d + 1;
  340.       _root.attachMovie("feeler","feelerClip",_root.d);
  341.       var _loc7_ = [];
  342.       var _loc9_ = 0;
  343.       var _loc11_ = this.dirArray.length;
  344.       while(_loc9_ < _loc11_)
  345.       {
  346.          _root.feelerClip._x = this.x + this.feelerInfo[_loc9_][0];
  347.          _root.feelerClip._y = this.y + this.feelerInfo[_loc9_][1];
  348.          _root.feelerClip._width = this.feelerInfo[_loc9_][2];
  349.          _root.feelerClip._height = this.feelerInfo[_loc9_][3];
  350.          var _loc3_ = 0;
  351.          var _loc8_ = _root.chars.length;
  352.          var _loc6_ = false;
  353.          while(_loc3_ < _loc8_)
  354.          {
  355.             var _loc5_ = _root.chars[_loc3_] + "Clip";
  356.             if(_root.feelerClip.hitTest(_root[_loc5_]))
  357.             {
  358.                var _loc4_ = _root.chars[_loc3_];
  359.                if(_root[_loc4_].matrixVar == 2 && _loc4_ != this.Name + this.id)
  360.                {
  361.                   _loc6_ = true;
  362.                   break;
  363.                }
  364.             }
  365.             _loc3_ = _loc3_ + 1;
  366.          }
  367.          if(!_loc6_)
  368.          {
  369.             var _loc10_ = _root.advanceDir != "L" ? "L" : "R";
  370.             if(this.dirArray[_loc9_] != _loc10_)
  371.             {
  372.                _loc7_.push(this.dirArray[_loc9_]);
  373.             }
  374.          }
  375.          _loc9_ = _loc9_ + 1;
  376.       }
  377.       _loc9_ = 0;
  378.       _loc11_ = _loc7_.length;
  379.       if(_loc9_ < _loc11_)
  380.       {
  381.          if(_loc7_[_loc9_] == _root.advanceDir)
  382.          {
  383.             return _root.advanceDir;
  384.          }
  385.          return _loc7_[random(_loc7_.length)];
  386.       }
  387.    }
  388.    function attacking()
  389.    {
  390.       this.xMovT *= 1.02;
  391.       this.yMovT *= 1.02;
  392.       if(random(100) > 93)
  393.       {
  394.          this[this.axis + "MovT"] = 0;
  395.          this.axis = this.axis != "x" ? "x" : "y";
  396.          this[this.axis + "MovT"] = random(2) <= 0 ? -1 * this.speed : this.speed;
  397.          this.getDirString();
  398.       }
  399.    }
  400.    function attacking2()
  401.    {
  402.       _root.fxID = _root.fxID + 1;
  403.       _root["batCStreak" + _root.fxID] = new classes.fx.BatCStreak(this.x,this.y,_root.fxID);
  404.       _root.addFX("batCStreak" + _root.fxID);
  405.    }
  406.    function death()
  407.    {
  408.       _root.stats.destroyed = _root.stats.destroyed + 1;
  409.       _root.stats.score += 10000;
  410.       _root.powerUp(this.x,this.y,94);
  411.       if(this.matrixVar == 1)
  412.       {
  413.          _root.matrixNum = _root.matrixNum + 1;
  414.          if(_root.matrixNum >= _root.matrixSize)
  415.          {
  416.             _root.matrixComplete = true;
  417.          }
  418.       }
  419.       var _loc3_ = 0;
  420.       var _loc4_ = _root["form" + this.form[0]].length;
  421.       while(_loc3_ < _loc4_)
  422.       {
  423.          if(_root["form" + this.form[0]][_loc3_] == "batC" + this.id)
  424.          {
  425.             _root["form" + this.form[0]].splice(_loc3_,1);
  426.             if(_root["form" + this.form[0]].length == 0)
  427.             {
  428.                delete _root["form" + this.form[0]];
  429.                if(_root["formB" + this.form[0]] == "matrixed")
  430.                {
  431.                   _loc3_ = 0;
  432.                   _loc4_ = random(3) + 1;
  433.                   while(_loc3_ < _loc4_)
  434.                   {
  435.                      _root.createPowerUp([this.x,this.y,"coin10"]);
  436.                      _loc3_ = _loc3_ + 1;
  437.                   }
  438.                   _root.stats.score += 10000;
  439.                }
  440.                else
  441.                {
  442.                   _root.createPowerUp([this.x,this.y,"coin25"]);
  443.                   _root.stats.score += 20000;
  444.                }
  445.                delete _root["formB" + this.form[0]];
  446.             }
  447.             break;
  448.          }
  449.          _loc3_ = _loc3_ + 1;
  450.       }
  451.       _root.createExploA([this.x + this.clip._width / 2,this.y + this.clip._height / 2,_root.randRange(80,130),_root.randRange(75,100),"Purple"]);
  452.       _root.audio.playLevel4("batX" + (random(2) + 1),_root.randRange(8,15));
  453.       var _loc5_ = 0;
  454.       var _loc6_ = random(3);
  455.       while(_loc5_ < _loc6_)
  456.       {
  457.          _root.createShrapnel([this.x + this.clip._width / 2,this.y + this.clip._height / 2,"batC","Purple"]);
  458.          _loc5_ = _loc5_ + 1;
  459.       }
  460.       _root.createEnemySoul([this.x + this.clip._width / 2,this.y + this.clip._height / 2,"blue"]);
  461.       _root.removeChar("batC" + this.id);
  462.       this.f2 = "";
  463.    }
  464.    function death2()
  465.    {
  466.       _root.removeChar("batC" + this.id);
  467.       this.f2 = "";
  468.    }
  469.    function advance()
  470.    {
  471.       this.dir = _root.advanceDir;
  472.       this.clip.body.gotoAndPlay("advance");
  473.       this.xMovT = _root.advanceDir != "L" ? 1 * (this.speed / 2) : -1 * (this.speed / 2);
  474.       this.f2 = "advancing";
  475.    }
  476.    function advancing()
  477.    {
  478.       this.c = this.c + 1;
  479.       if(this.c > this.advanceMax)
  480.       {
  481.          this.xMovT = 0;
  482.          this.c = 0;
  483.          this.f2 = "wait";
  484.          _root.d = _root.d + 1;
  485.          _root.attachMovie("sight","sightClip",_root.d);
  486.          _root.sightClip.gotoAndStop("hindSight");
  487.          _root.sightClip._x = this.x;
  488.          _root.sightClip._y = this.y;
  489.          if(_root.advanceDir == "L")
  490.          {
  491.             _root.sightClip._rotation = 180;
  492.          }
  493.          if(_root.sightClip.hitTest(_root[_root.char].x,_root[_root.char].y,true))
  494.          {
  495.             _root.broBehind();
  496.          }
  497.          removeMovieClip(_root.sightClip);
  498.       }
  499.    }
  500.    function wander()
  501.    {
  502.       if(random(100) > 90 + _root.dif.wander)
  503.       {
  504.          this[this.axis + "MovT"] = 0;
  505.          this.axis = this.axis != "x" ? "x" : "y";
  506.          this[this.axis + "MovT"] = random(2) <= 0 ? -1 * this.speed : this.speed;
  507.          this.getDirString();
  508.       }
  509.    }
  510.    function main()
  511.    {
  512.       this[this.f2]();
  513.       if(this.oldDir != this.dir)
  514.       {
  515.          this.clip.gotoAndStop("fly" + this.dir);
  516.       }
  517.       this.oldDir = this.dir;
  518.       if(this.nudging)
  519.       {
  520.          this.xA *= 0.5;
  521.          this.yA *= 0.5;
  522.          this.nc = this.nc + 1;
  523.          var _loc8_ = 255 - this.nc * 17;
  524.          this.colorTrans.greenOffset = _loc8_;
  525.          this.colorTrans.blueOffset = _loc8_ / 2;
  526.          this.trans.colorTransform = this.colorTrans;
  527.          if(this.nc == 15)
  528.          {
  529.             this.xA = this.yA = 0;
  530.             this.nudging = false;
  531.             this.colorTrans.greenOffset = this.colorR;
  532.             this.colorTrans.blueOffset = this.colorR;
  533.             this.trans.colorTransform = this.colorTrans;
  534.          }
  535.       }
  536.       var _loc4_ = 0;
  537.       var _loc7_ = _root.broShots.length;
  538.       while(_loc4_ < _loc7_)
  539.       {
  540.          var _loc6_ = _root.broShots[_loc4_] + "Clip";
  541.          if(this.clip.hitTest(_root[_loc6_]))
  542.          {
  543.             var _loc3_ = _root.broShots[_loc4_];
  544.             var _loc5_ = this.life;
  545.             this.life -= _root[_loc3_].power;
  546.             if(this.life < 1)
  547.             {
  548.                this.f2 = "death";
  549.             }
  550.             else
  551.             {
  552.                this.nudge(_root[_loc3_].xMov,_root[_loc3_].yMov,10);
  553.                _root.audio.playLevel4("batHit" + (random(2) + 1),_root.randRange(10,20));
  554.             }
  555.             _root[_root.char].fc = _root[_root.char].fireFreq - _root.rapidVar;
  556.             _root[_loc3_].exploX = this.x + this.clip._width / 2;
  557.             _root[_loc3_].exploY = this.y + this.clip._height / 2;
  558.             _root[_loc3_].hit(_loc5_);
  559.             break;
  560.          }
  561.          _loc4_ = _loc4_ + 1;
  562.       }
  563.       if(this.clip.hitTest(_root[_root.char + "Clip"]))
  564.       {
  565.          _root[_root.char].hit(this.xMov,this.yMov,100,this.power);
  566.          this.f2 = "death";
  567.       }
  568.       if(this.x > 1050 || this.x < -50 || this.y < -50 || this.y > 650)
  569.       {
  570.          delete _root["form" + this.form[0]];
  571.          delete _root["formB" + this.form[0]];
  572.          this.f2 = "death2";
  573.       }
  574.       if(this.xMovT < this.xMov)
  575.       {
  576.          this.xMov -= this.cv;
  577.       }
  578.       else if(this.xMovT > this.xMov)
  579.       {
  580.          this.xMov += this.cv;
  581.       }
  582.       else
  583.       {
  584.          this.xMov = this.xMovT;
  585.       }
  586.       if(this.yMovT < this.yMov)
  587.       {
  588.          this.yMov -= this.cv;
  589.       }
  590.       else if(this.yMovT > this.yMov)
  591.       {
  592.          this.yMov += this.cv;
  593.       }
  594.       else
  595.       {
  596.          this.yMov = this.yMovT;
  597.       }
  598.       this.xmt = this.xMov;
  599.       this.ymt = this.yMov;
  600.       if(random(10) == 1)
  601.       {
  602.          if(this.axis == "y")
  603.          {
  604.             this.xmt += _root.randRange2(-1,1);
  605.          }
  606.          else
  607.          {
  608.             this.ymt += _root.randRange2(-1,1);
  609.          }
  610.       }
  611.       this.x += this.xmt + this.xA;
  612.       this.y += this.ymt + this.yA;
  613.       this.clip._x = this.x;
  614.       this.clip._y = this.y;
  615.    }
  616. }
  617.